package client;

import interfaces.*;
import client.*;
import serveur.*;
import java.rmi.*; 
import java.util.*; 
import java.rmi.server.UnicastRemoteObject;
import java.io.*;

public class TokenImpl extends UnicastRemoteObject implements TokenITF {

	// Initiateur du jeton & capacité
	ClientITF sender;
	
	int id_max;
	int capa_max;
	
	// Liste des personnes ayant vu le jeton
	Vector<ClientITF> have_seen = new Vector<ClientITF>();
	
	public TokenImpl(ClientITF client) throws RemoteException
	{
		sender    = client;
		
		// Pour l'instant, le sender est "élu"
		id_max    = client.getID();
		capa_max  = client.getCapacity();
		
		// Le client de départ est mis dans la liste 
		// de ceux qui ont déjà vu le jeton
		addHaveSeen(client);
	}
	
	public int getSender() throws RemoteException
	{
		return sender.getID();
	}
	
	public ClientITF getSenderITF() throws RemoteException
	{
		return sender;
	}
	
	public void setIdMax(int id) throws RemoteException
	{
		id_max = id;
	}
	
	public int getIdMax() throws RemoteException
	{
		return id_max;
	}
	
	public void setCapacityMax(int cm) throws RemoteException
	{
		capa_max = cm;
	}
	
	public int getCapacityMax() throws RemoteException
	{
		return capa_max;
	}
	
	public void addHaveSeen(ClientITF client) throws RemoteException
	{
		have_seen.add(client);
	}
	
	public Vector getHaveSeen() throws RemoteException
	{
		return have_seen;
	}
	
	public boolean hadBeenSeen(ClientITF client) throws RemoteException
	{
		for (ClientITF c : (Vector<ClientITF>) have_seen)
		{
			if (c.equals(client))
			{
				return true;
			}
		}
	
		return false;
	}
}
